# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=emp3r0r
pkgver=v3.4.2.r6.g87edc10e
pkgrel=1
pkgdesc='Linux post-exploitation framework made by linux user.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-automation')
url='https://github.com/jm33-m0/emp3r0r'
license=('MIT')
depends=('tmux' 'bash')
makedepends=('git' 'go')
source=("git+https://github.com/jm33-m0/emp3r0r.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

build_cmd() {
  cd core && go mod tidy &&

  cd "cmd/$1" && CGO_ENABLED=0 go build -o "../../../$2" -ldflags='-s -w -v'
}

build() {
  cd $pkgname

  (build_cmd 'cc' emp3r0r-cc) &&
  (build_cmd 'cat' emp3r0r-cat) &&
  (build_cmd 'agent' stub.exe) &&
  (GOOS=windows build_cmd 'agent' stub-win.exe)
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/lib/$pkgname/build"

  install -Dm 755 emp3r0r-cc "$pkgdir/usr/lib/$pkgname"
  install -Dm 755 emp3r0r-cat "$pkgdir/usr/lib/$pkgname"
  install -Dm 755 ./*.exe "$pkgdir/usr/lib/$pkgname/build"
  install -Dm 755 "./core/$pkgname" "$pkgdir/usr/bin/$pkgname"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  # extra files
  cp -r ./core/tmux "$pkgdir/usr/lib/$pkgname"
  cp -r ./core/modules "$pkgdir/usr/lib/$pkgname"
}

